﻿using System;
using ReadingList.Contracts.DataContracts.QueryParameters;
using ReadingList.Contracts.DataContracts.QueryResults;
using ReadingList.Contracts.ServiceContracts;
using ReadingList.Entities;
using ReadingList.DataAccess.EntityFramework;

namespace ReadlingList.Services
{
    public class UserService : IUserService
    {

        private readonly IEntityFrameworkRepository mRepository;

        public UserService() {

        }

        public UserService(IEntityFrameworkRepository repository) {
            mRepository = repository;
        }

        public UserQueryResult FindUserByUsername(UserQueryParameter queryParameter) {
            var result = Map(mRepository.FindUserByUserName(queryParameter.Username));

            return result;
        }

        private Func<User, UserQueryResult> Map = result => {
            return new UserQueryResult
                       {
                           Username = result.Username,
                           FirstName = result.FirstName,
                           LastName = result.LastName

                       };
        };
    }
}
